package cn.edu.zafu.bigdata.x.hjn;

import java.util.Scanner;
import java.util.Random;

public class GuessNumberGame {
    private static final int MAX_TRIES = 5;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        boolean playAgain;

        do {
            int numberToGuess = random.nextInt(100) + 1;
            int tries = 0;
            boolean hasGuessedCorrectly = false;

            System.out.println("这是一个猜数字游戏！你有 " + MAX_TRIES + " 次机会来猜一个 1 到 100 之间的数字。");

            while (tries < MAX_TRIES && !hasGuessedCorrectly) {
                System.out.print("你猜的数字是: ");
                int playerGuess = scanner.nextInt();
                tries++;

                if (playerGuess < numberToGuess) {
                    System.out.println("哥们，太小了！");
                } else if (playerGuess > numberToGuess) {
                    System.out.println("哇哦，太大了！");
                } else {
                    hasGuessedCorrectly = true;
                    System.out.println("牛逼哥们！猜对了！");
                }
            }

            if (!hasGuessedCorrectly) {
                System.out.println("菜就多练！正确答案是 " + numberToGuess + "。");
            }

            System.out.print("小哥哥，还想再玩一次吗？（y/n）: ");
            playAgain = scanner.next().equalsIgnoreCase("y");

        } while (playAgain);

        System.out.println("不玩就滚！");
        scanner.close();
    }
}
